/// <summary>
// CodeFx.MySqlProviders - .NET Providers for MySql using the framework CodeFx
// Laurent Morisseau
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Laurent Morisseau
/// </summary>
/// <author><a href="mailto:laurent.morisseau@gmail.com">Laurent Morisseau</a></author>


namespace CodeFx.MySqlProviders
{
    using System;
    using System.Text;
    using System.Web;
    using System.Data;
    using System.ComponentModel;
    using MySql.Data.MySqlClient;
    using System.Collections;
    using CodeFx;
    using CodeFx.Web;

    internal static partial class Aspnet_personalizationallusersDTO
    {

        internal static void Delete_ShareState(uint ApplicationId, string Path)
        {
            const string command = "DELETE u FROM aspnet_personalizationallusers u inner join aspnet_paths p on (p.PathId = u.PathId and p.Path = ?Path and p.ApplicationId = ?ApplicationId)";
            MySqlConnection conn = ConnectionString.Current.OpenConnection; 
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?ApplicationId", ApplicationId));
            cmd.Parameters.Add(new MySqlParameter("?Path", Path));
            try
            {
                cmd.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }

        internal static void Delete_AllState(uint ApplicationId)
        {
            const string command="DELETE u FROM aspnet_personalizationallusers u inner join aspnet_Paths P on (p.PathId = u.PathId and P.ApplicationId=?ApplicationId)";
            MySqlConnection conn = ConnectionString.Current.OpenConnection;       
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?ApplicationId", ApplicationId));
            try
            {

                cmd.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }

        internal static Byte[] Select_PathId(uint PathId)
        {
            byte[] pagesettings = null;
            string command = "SELECT p.PageSettings FROM aspnet_personalizationallusers p WHERE p.PathId = ?PathId ";
            MySqlConnection conn = ConnectionString.Current.OpenConnection;       
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", PathId));
            MySqlDataReader dr = null;
            try
            {
                dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                if (dr.Read())
                {
                    pagesettings = dr.GetValue(0) as byte[];
                }
            }
            catch (Exception ex)
            {
                throw new DALException(cmd.CommandText, ex.InnerException);
            }
            finally
            {
                if (dr != null)
                    dr.Close();
                conn.Close();
            }
            return pagesettings;

        }

        [DataObjectMethodAttribute(DataObjectMethodType.Delete, false)]
        internal static void DeleteByFk_PathId(uint pathid)
        {

            string command = "delete from aspnet_personalizationallusers where PathId =?PathId";
            MySqlConnection conn = ConnectionString.Current.OpenConnection;       
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", pathid));
            try
            {
                cmd.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }
     
    }
}